package tools

import (
	"encoding/json"
	"zzxq/common/codes"
	"zzxq/common/setting"

	"github.com/gin-gonic/gin"
)

var ginFast = setting.GinFast{
	MemCreat:   false,
	MemRunTime: 30000,
	AESKey:     "Z0T+BwMXisO5bMZb",
	AESIvData:  "eN6$nM4~kS4[aS1`iF",
}

//ResponseData 数据返回结构体
type ResponseData struct {
	STATUS int         `json:"status"`
	MSG    string      `json:"msg"`
	Data   interface{} `json:"data"`
}

func InitGinFast() {
	conf := setting.Config.GinFast
	ginFast = conf
}

func IsMemCreat() bool {
	return ginFast.MemCreat
}

func SetFastResp(c *gin.Context, code int, data interface{}) {

	resp := ResponseData{
		STATUS: code,
		MSG:    codes.GetMsg(code),
		Data:   data,
	}

	respByte, _ := json.Marshal(&resp)
	c.Set("resp", string(respByte))
}
